package br.com.stefanini.schs.ejb.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;

@Entity
@Table(name = "ponto")
@NamedQueries({
	@NamedQuery(name="Ponto.consultarTodosPontos", query="Select p From Ponto p"),
	@NamedQuery(name="Ponto.consultarTodosPontoDoFuncionario", query="SELECT p from Ponto p WHERE p.funcionario.idFuncionario = :idFuncionario"),
	@NamedQuery(name="Ponto.consultarPontoFuncionario", query="SELECT p from Ponto p WHERE p.idPonto = :idPonto")
})
public class Ponto implements Serializable{

	private static final long serialVersionUID = 1L;

	//define chave primaria
	@Id
	@SequenceGenerator(name="idPonto", sequenceName="idPonto", allocationSize = 1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "idPonto")
	@Column(name = "idPonto")
	private long idPonto;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "horaEntrada")
	private Date horaEntrada;
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "horaSaida")
	private Date horaSaida;
	@Column(name = "horaIntervalo")
	private Date horaIntervalo;
	
//***********************relacionamentos*********************** 
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name="fk_idFuncionario",insertable=true,updatable =true)
	@Fetch(org.hibernate.annotations.FetchMode.JOIN)
	@Cascade(org.hibernate.annotations.CascadeType.ALL)
	private Funcionario funcionario;
	
	@OneToMany(mappedBy = "ponto",fetch = FetchType.LAZY)
	@Cascade(CascadeType.REMOVE)
	private Collection<Atividade> atividades;
	
	
//***********************relacionamentos*********************** 
	
	public Date getHoraEntrada() {
		return horaEntrada;
	}

	public void setHoraEntrada(Date horaEntrada) {
		this.horaEntrada = horaEntrada;
	}

	public Collection<Atividade> getAtividades() {
		return atividades;
	}

	public void setAtividades(Collection<Atividade> atividades) {
		this.atividades = atividades;
	}

	public Date getHoraSaida() {
		return horaSaida;
	}

	public void setHoraSaida(Date horaSaida) {
		this.horaSaida = horaSaida;
	}

	public Date getHoraIntervalo() {
		return horaIntervalo;
	}

	public void setHoraIntervalo(Date horaIntervalo) {
		this.horaIntervalo = horaIntervalo;
	}
	
	public long getIdPonto() {
		return idPonto;
	}

	public void setIdPonto(long idPonto) {
		this.idPonto = idPonto;
	}

	public Funcionario getFuncionario() {
		return funcionario;
	}

	public void setFuncionario(Funcionario funcionario) {
		this.funcionario = funcionario;
	}
}
